//
//  SegmentControlViewController.m
//  SegmentControl
//

#import "SegmentControlViewController.h"

@implementation SegmentControlViewController

- (void)segmentClick:(id)sender {
	NSLog(@"clicked: %d", [sender selectedSegmentIndex]);
}

- (void)viewDidLoad {
	
	NSArray *arrSegments = [[NSArray alloc] initWithObjects:
							[NSString stringWithString:@"0"],
							[NSString stringWithString:@"1"],
							[NSString stringWithString:@"2"], nil];
	
	UISegmentedControl *mySegment
	= [[UISegmentedControl alloc] initWithItems:arrSegments];

	[mySegment setFrame:CGRectMake(10,50,300,40)];
	
	[mySegment addTarget:self
				  action:@selector(segmentClick:)
		forControlEvents:UIControlEventValueChanged];
	
	[mySegment setSegmentedControlStyle:UISegmentedControlStyleBar];
	[mySegment setTintColor:[UIColor darkGrayColor]];
	
	// 첫 번째 항목 선택
	[mySegment setSelectedSegmentIndex:0];
	
	// 세그먼트 크기 변경
	[mySegment setWidth:120.0 forSegmentAtIndex:1];
	
	// 세그먼트 추가
	[mySegment insertSegmentWithTitle:@"new" atIndex:2 animated:YES];
	
	[self.view addSubview:mySegment];
	[arrSegments release];
	[mySegment release];
}

- (void)dealloc {
    [super dealloc];
}

@end
